import  requests
from bs4 import BeautifulSoup
class dbpc():
    def __init__(self,url):
        pass
    @classmethod
    def dtloan(cls):
        #链接 因为是动态加载得数据所有链接改变
        url='https://movie.douban.com/j/chart/top_list'
        # 参数
        params={
            'type': '5',
            'interval_id': '100:90',
            'action':'' ,
            'start':'0',
            'limit': '20',
        }
        headers={
            'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
        }
        response=requests.get(url=url,params=params,headers=headers)
        response.encoding='utf-8'
        # 将获取字符串格式json数据序列化成字典或者列表对象
        page_text=response.json()
        for movie in page_text:
            name=movie['title']
            score=movie['score']
            print(name,score)
    @classmethod
    def bsloan(cls):
        '''使用BeautifulSoup 动态加载没有查看到电影信息'''
        # 链接
        url = 'https://movie.douban.com/typerank'
        #参数
        params={
            'type_name' : '动作' ,
            'type' : '5' ,
            'interval_id' : '100:90 ',
            'action' :'',
        }
        headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
        }
        response=requests.get(url=url,params=params,headers=headers)
        response.encoding='utf-8'
        soup = BeautifulSoup(response.text, 'html.parser')  # lxml为解析器
        print(soup)

if __name__ == '__main__':
     # 动态获取
     dbpc.dtloan()
     #使用BeautifulSoup
     # dbpc.bsloan()